package wx.actions;

import com.jinyou.utils.common.DateUtils;
import com.jinyou.utils.common.ValidateUtil;
import o2o.cache.sys.SysConfigPayMemory;
import o2o.dao.PO.sys.SysConfigPay;
import pay.config.WeixinConfig;
import wx.dao.WXMsgTemplate;
import wx.utils.gzh.WXGZHMan;

import java.util.HashMap;

public class WxGzhActionMan {


    //公众号模板消息
    public static void sendGzhMsg(String sysAppKey,String appFlag,String toUserGzhOpenId, String templateId, String title, String price, String status, String statusDetail) {
        HashMap<String, String> xcxMap = null;

        String xcxAppId = WeixinConfig.xcxAppId;
        String gzhAppId = WeixinConfig.gzhAppId;
        String gzhAppSecret = WeixinConfig.gzhAppSecret;
        if (ValidateUtil.isNotNull(appFlag)) {
            SysConfigPay sysConfigPay = SysConfigPayMemory.getInstance().getByKey(sysAppKey, appFlag);
            if (null != sysConfigPay) {
                xcxAppId = sysConfigPay.getWxXcxAppId();
                gzhAppId = sysConfigPay.getWxGzhAppId();
                gzhAppSecret = sysConfigPay.getWxGzhAppSecret();
            }
        }

        //需要跳转的小程序
        if (ValidateUtil.isNotNull(xcxAppId)) {
            xcxMap = new HashMap<>();
            xcxMap.put("appid", xcxAppId);
            xcxMap.put("pagepath", "pages/index-new/index-new");
        }

        HashMap dataMap = new HashMap();
        dataMap.put("first", new WXMsgTemplate(title));
        dataMap.put("keyword1", new WXMsgTemplate(price));
        dataMap.put("keyword2", new WXMsgTemplate(DateUtils.getCurrentDateTime()));
        dataMap.put("keyword3", new WXMsgTemplate(status));
        dataMap.put("remark", new WXMsgTemplate(statusDetail));

        WXGZHMan.pushGzhMsg(gzhAppId, gzhAppSecret,
                toUserGzhOpenId, templateId,
                null, null,
                xcxMap,
                dataMap);
    }


}
